package com.wechat.controller.wechat;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.wechat.utils.HTTPGet;

public class WechatIndexController extends Controller {
	
	public void index(){
		render("index.html");
	}
	
	public void getCarViolation(){
		String html = HTTPGet.get("http://www.wfcx123.com/wfcx.php?hpzl=02&hphm=%E9%B2%81BXX501", "utf-8");
		
		String b = "";
		List list = new ArrayList<>();
		try {
			b = URLDecoder.decode(html,"gb2312");
			
			String[] line = b.split("[||]");
			
			for (String s : line) {
				if(s.length() > 3){
					s = s.substring(0, s.length()-4);
					String[] ss = s.split("[$$]");
					
					Map<String, String> map = new HashMap<String, String>();
					
					for (int i=0;i<ss.length;i++) {
						String sa = ss[i];
						if(sa.length() > 0 && !sa.isEmpty()){
							map.put(i+"", sa);
						}
					}
					
					list.add(map);
					
				}
				
			}
			
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		
		
		renderJson(list);
	}
}
